{%- include reset/languages.liquid -%}

{% comment %} Set default lang {% endcomment %}
{%- assign site_lang = "en" -%}
{%- if languages contains site.lang -%}
    {%- assign site_lang = site.lang -%}
{%- endif -%}

{% comment %} Get docs all avaiable langs {% endcomment %}
{%- capture langs -%}
    {{ site_lang }}|
    {%- for item in site_dirs -%}
        {%- assign chapter = item.dir | remove_first: "/" | split: "/" | first -%}
        {%- if languages contains chapter -%}
            {{ chapter }}|
        {%- endif -%}
    {%- endfor -%}
{%- endcapture -%}
{%- assign site_langs = langs | split: "|" | uniq -%}

{% comment %} include language by the root subdirectory {% endcomment %}
{%- assign lang = site_lang -%}

{%- if page.dir != "/" -%}
    {%- assign chapter = page.dir | remove_first: "/" | split: "/" | first -%}
    {%- if languages contains chapter -%}
        {%- assign lang = chapter -%}
    {%- endif -%}
{%- endif -%}

{%- include i18n/{{ lang }}.liquid -%}
